//
//  JKBaseTableView.swift
//  ZhiHuDaily-Swift
//
//  Created by albert on 2018/3/2.
//  Copyright © 2018年 安永博. All rights reserved.
//

import UIKit
import MJRefresh

class JKBaseTableView: UITableView {

    var mainHeaderView: UIView?
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        guard let _ = mainHeaderView else { return }
        
        if (contentOffset.y > JKScreenH) {
            return;
        }
        
        sendSubview(toBack: mainHeaderView!)
    }
    
    /** 添加header刷新控件 */
    func addHeaderWithRefreshingTarget(target: Any, refreshingAction: Selector) {
        
        if mj_header != nil {
            return
        }
        
        mj_header = MJRefreshNormalHeader(refreshingTarget: target, refreshingAction: refreshingAction)
        self.mj_header.isAutomaticallyChangeAlpha = true
    }
    
    /** 添加footer刷新控件 */
    func addFooterWithRefreshingTarget(target: Any, refreshingAction: Selector) {
        
        if mj_footer != nil {
            return
        }
        
        mj_footer = MJRefreshAutoNormalFooter(refreshingTarget: target, refreshingAction: refreshingAction)
        mj_footer.isHidden = true
    }
}
